﻿using CUREBusinessLogicLayer.Harmful;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CURE.Handler
{
    /// <summary>
    /// ExpHandler 的摘要说明
    /// </summary>
    public class ExpHandler : IHttpHandler
    {
        #region 实验申请变量
        private string mid;

        public string Mid
        {
            get { return mid; }
            set { mid = value; }
        }
        private string fid;

        public string Fid
        {
            get { return fid; }
            set { fid = value; }
        }
        
        private string reason;

        public string Reason
        {
            get { return reason; }
            set { reason = value; }
        }

        private string action;

        public string Action
        {
            get { return action; }
            set { action = value; }
        }

        private string judgename;//判定名称

        public string Judgename
        {
            get { return judgename; }
            set { judgename = value; }
        }
        private string typeno;//型号

        public string Typeno
        {
            get { return typeno; }
            set { typeno = value; }
        }
        private string mcno;//机台别

        public string Mcno
        {
            get { return mcno; }
            set { mcno = value; }
        }
        private string startbt;//F卡bt号 开始

        public string Startbt
        {
            get { return startbt; }
            set { startbt = value; }
        }
        private string endbt;//F卡bt号 结束

        public string Endbt
        {
            get { return endbt; }
            set { endbt = value; }
        }
        private string num;//发生数量

        public string Num
        {
            get { return num; }
            set { num = value; }
        }
        private string fdate;//F卡生产时间

        public string Fdate
        {
            get { return fdate; }
            set { fdate = value; }
        }
        private string desc;//橡胶外观目视描述

        public string Desc
        {
            get { return desc; }
            set { desc = value; }
        }

        private string rubberput;//材料放置点

        public string Rubberput
        {
            get { return rubberput; }
            set { rubberput = value; }
        }

        private string cont;//内容

        public string Cont
        {
            get { return cont; }
            set { cont = value; }
        }
        private string cate;//精炼不良类别

        public string Cate
        {
            get { return cate; }
            set { cate = value; }
        }
        private string deviceabnormal;//设备异常

        public string Deviceabnormal
        {
            get { return deviceabnormal; }
            set { deviceabnormal = value; }
        }
        private string devicecontent;//设备异常内容

        public string Devicecontent
        {
            get { return devicecontent; }
            set { devicecontent = value; }
        }
        private string skillabnormal;//技能员异常

        public string Skillabnormal
        {
            get { return skillabnormal; }
            set { skillabnormal = value; }
        }
        private string skillcontent;//技能员异常内容

        public string Skillcontent
        {
            get { return skillcontent; }
            set { skillcontent = value; }
        }
        private string lotabnormal;//lot异常

        public string Lotabnormal
        {
            get { return lotabnormal; }
            set { lotabnormal = value; }
        }
        private string lotcontent;//lot异常内容

        public string Lotcontent
        {
            get { return lotcontent; }
            set { lotcontent = value; }
        }
        private string workabnormal;//作业录像异常

        public string Workabnormal
        {
            get { return workabnormal; }
            set { workabnormal = value; }
        }
        private string workcontent;//作业录像异常内容

        public string Workcontent
        {
            get { return workcontent; }
            set { workcontent = value; }
        }
        private string rubberno;//橡胶型号

        public string Rubberno
        {
            get { return rubberno; }
            set { rubberno = value; }
        }
        private string rubberlotno;//橡胶批次

        public string Rubberlotno
        {
            get { return rubberlotno; }
            set { rubberlotno = value; }
        }
        private string rubbernum;//橡胶应保留数

        public string Rubbernum
        {
            get { return rubbernum; }
            set { rubbernum = value; }
        }
        private string rubberrealnum;//橡胶实际保留数

        public string Rubberrealnum
        {
            get { return rubberrealnum; }
            set { rubberrealnum = value; }
        }
        private string elementno;//部材型号

        public string Elementno
        {
            get { return elementno; }
            set { elementno = value; }
        }
        private string elementlotno;//部材批次

        public string Elementlotno
        {
            get { return elementlotno; }
            set { elementlotno = value; }
        }
        private string elementnum;//部材应保留数

        public string Elementnum
        {
            get { return elementnum; }
            set { elementnum = value; }
        }
        private string elementrealnum;//部材实际保留数

        public string Elementrealnum
        {
            get { return elementrealnum; }
            set { elementrealnum = value; }
        }
        private string tireno;//生胎型号

        public string Tireno
        {
            get { return tireno; }
            set { tireno = value; }
        }
        private string tirelotno;//生胎批次

        public string Tirelotno
        {
            get { return tirelotno; }
            set { tirelotno = value; }
        }
        private string tirenum;//生胎应保留数

        public string Tirenum
        {
            get { return tirenum; }
            set { tirenum = value; }
        }
        private string tirerealnum;//生胎实际保留数

        public string Tirerealnum
        {
            get { return tirerealnum; }
            set { tirerealnum = value; }
        }
        private string prono;//制品型号

        public string Prono
        {
            get { return prono; }
            set { prono = value; }
        }
        private string prolotno;//制品批次

        public string Prolotno
        {
            get { return prolotno; }
            set { prolotno = value; }
        }
        private string pronum;//制品应保留数

        public string Pronum
        {
            get { return pronum; }
            set { pronum = value; }
        }
        private string prorealnum;//制品实际保留数

        public string Prorealnum
        {
            get { return prorealnum; }
            set { prorealnum = value; }
        }
        private string remarks;//备注

        public string Remarks
        {
            get { return remarks; }
            set { remarks = value; }
        }

        #endregion

        #region 实验结果变量
        private string sulspec;

        public string Sulspec
        {
            get { return sulspec; }
            set { sulspec = value; }
        }
        private string sulactual;

        public string Sulactual
        {
            get { return sulactual; }
            set { sulactual = value; }
        }
        private string suljudge;

        public string Suljudge
        {
            get { return suljudge; }
            set { suljudge = value; }
        }
        private string weightspec;

        public string Weightspec
        {
            get { return weightspec; }
            set { weightspec = value; }
        }
        private string weightactual;

        public string Weightactual
        {
            get { return weightactual; }
            set { weightactual = value; }
        }
        private string weightjudge;

        public string Weightjudge
        {
            get { return weightjudge; }
            set { weightjudge = value; }
        }
        private string rpagspec;

        public string Rpagspec
        {
            get { return rpagspec; }
            set { rpagspec = value; }
        }
        private string rpaactual;

        public string Rpaactual
        {
            get { return rpaactual; }
            set { rpaactual = value; }
        }
        private string rpajudge;

        public string Rpajudge
        {
            get { return rpajudge; }
            set { rpajudge = value; }
        }
        private string rpatsspec;

        public string Rpatsspec
        {
            get { return rpatsspec; }
            set { rpatsspec = value; }
        }
        private string rpatsactual;

        public string Rpatsactual
        {
            get { return rpatsactual; }
            set { rpatsactual = value; }
        }
        private string rpatsjudge;

        public string Rpatsjudge
        {
            get { return rpatsjudge; }
            set { rpatsjudge = value; }
        }
        private string bpspec;

        public string Bpspec
        {
            get { return bpspec; }
            set { bpspec = value; }
        }
        private string bpactual;

        public string Bpactual
        {
            get { return bpactual; }
            set { bpactual = value; }
        }
        private string bpjudge;

        public string Bpjudge
        {
            get { return bpjudge; }
            set { bpjudge = value; }
        }
        private string resultremarks;

        public string Resultremarks
        {
            get { return resultremarks; }
            set { resultremarks = value; }
        }

        private string page;

        public string Page1
        {
            get { return page; }
            set { page = value; }
        }
        #endregion

        private LedgerBll ledgerbll = new LedgerBll();

        public void ProcessRequest(HttpContext context)
        {
            Mid = context.Request.Form["id"];
            Fid = context.Request.Form["fid"];
            Action = context.Request.Form["action"];
            Reason = context.Request.Form["reason"];
            Judgename = context.Request.Form["judgename"];
            Typeno = context.Request.Form["typeno"];
            Mcno = context.Request.Form["mcno"];
            Startbt = string.IsNullOrEmpty(context.Request.Form["startbt"]) ? "0" : context.Request.Form["startbt"];
            Endbt = string.IsNullOrEmpty(context.Request.Form["endbt"]) ? "0" : context.Request.Form["endbt"];
            Num = string.IsNullOrEmpty(context.Request.Form["num"]) ? "0" : context.Request.Form["num"];
            Fdate = context.Request.Form["fdate"]; 
            Desc = context.Request.Form["desc"];
            Rubberput = context.Request.Form["rubberput"];
            Cont = context.Request.Form["cont"];
            Cate = context.Request.Form["badcate"];
            Deviceabnormal = context.Request.Form["deviceabnormal"];
            Devicecontent = context.Request.Form["devicecontent"];
            Skillabnormal = context.Request.Form["skillabnormal"];
            Skillcontent = context.Request.Form["skillcontent"];
            Lotabnormal = context.Request.Form["lotabnormal"];
            Lotcontent = context.Request.Form["lotcontent"];
            Workabnormal = context.Request.Form["workabnormal"];
            Workcontent = context.Request.Form["workcontent"];
            Rubberno = context.Request.Form["rubberno"];
            Rubberlotno = context.Request.Form["rubberlot"];
            Rubbernum = string.IsNullOrEmpty(context.Request.Form["rubbernum"]) ? "0" : context.Request.Form["rubbernum"];
            Rubberrealnum = string.IsNullOrEmpty(context.Request.Form["rubberreal"]) ? "0" : context.Request.Form["rubberreal"];
            Elementno = context.Request.Form["eleno"];
            Elementlotno = context.Request.Form["elelot"];
            Elementnum = string.IsNullOrEmpty(context.Request.Form["elenum"]) ? "0" : context.Request.Form["elenum"];
            Elementrealnum = string.IsNullOrEmpty(context.Request.Form["elereal"]) ? "0" : context.Request.Form["elereal"];
            Tireno = context.Request.Form["tireno"];
            Tirelotno = context.Request.Form["tirelot"];
            Tirenum = string.IsNullOrEmpty(context.Request.Form["tirenum"]) ? "0" : context.Request.Form["tirenum"];
            Tirerealnum = string.IsNullOrEmpty(context.Request.Form["tirereal"]) ? "0" : context.Request.Form["tirereal"];
            Prono = context.Request.Form["prono"];
            Prolotno = context.Request.Form["prolot"];
            Pronum = string.IsNullOrEmpty(context.Request.Form["pronum"]) ? "0" : context.Request.Form["pronum"];
            Prorealnum = string.IsNullOrEmpty(context.Request.Form["proreal"]) ? "0" : context.Request.Form["proreal"];
            Remarks = context.Request.Form["remark"];
            Page1=context.Request.Form["page"];

            

            

            string state = "4";
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("id", Mid);
            dic.Add("reason", Reason);
            dic.Add("fid", Fid);
            dic.Add("state", state);
            dic.Add("judgename", Judgename);
            dic.Add("typeno", Typeno);
            dic.Add("mcno", Mcno);
            dic.Add("startbt", Startbt);
            dic.Add("endbt", Endbt);
            dic.Add("num", Num);
            dic.Add("fdate", Fdate);
            dic.Add("desc", Desc);
            dic.Add("rubberput", Rubberput);
            dic.Add("cont", Cont);
            dic.Add("cate", Cate);
            dic.Add("deviceabnormal", Deviceabnormal);
            dic.Add("devicecontent", Devicecontent);
            dic.Add("skillabnormal", Skillabnormal);
            dic.Add("skillcontent", Skillcontent);
            dic.Add("lotabnormal", Lotabnormal);
            dic.Add("lotcontent", Lotcontent);
            dic.Add("workabnormal", Workabnormal);
            dic.Add("workcontent", Workcontent);
            dic.Add("rubberno", Rubberno);
            dic.Add("rubberlot", Rubberlotno);
            dic.Add("rubbernum", Rubbernum);
            dic.Add("rubberreal", Rubberrealnum);
            dic.Add("eleno", Elementno);
            dic.Add("elelot", Elementlotno);
            dic.Add("elenum", Elementnum);
            dic.Add("elereal", Elementrealnum);
            dic.Add("tireno", Tireno);
            dic.Add("tirelot", Tirelotno);
            dic.Add("tirenum", Tirenum);
            dic.Add("tirereal", Tirerealnum);
            dic.Add("prono", Prono);
            dic.Add("prolot", Prolotno);
            dic.Add("pronum", Pronum);
            dic.Add("proreal", Prorealnum);
            dic.Add("remark", Remarks);
            dic.Add("page", Page1);

            if (Page1 == "ExpList")
            {
                Sulspec = context.Request.Form["sulspec"];
                Sulactual = context.Request.Form["sulactual"];
                Suljudge = context.Request.Form["suljudge"];
                Weightspec = context.Request.Form["wspec"];
                Weightactual = context.Request.Form["wactual"];
                Weightjudge = context.Request.Form["wjudge"];
                Rpagspec = context.Request.Form["gspec"];
                Rpaactual = context.Request.Form["gactual"];
                Rpajudge = context.Request.Form["gjudge"];
                Rpatsspec = context.Request.Form["tsspec"];
                Rpatsactual = context.Request.Form["tsactual"];
                Rpatsjudge = context.Request.Form["tsjudge"];
                Bpspec = context.Request.Form["bpspec"];
                Bpactual = context.Request.Form["bpactual"];
                Bpjudge = context.Request.Form["bpjudge"];
                Resultremarks = context.Request.Form["resultremark"];

                dic.Add("SULFURSPEC", Sulspec);
                dic.Add("SULFULACTUAL", Sulactual);
                dic.Add("SULFULJUDGE", Suljudge);
                dic.Add("WEIGHTSPEC", Weightspec);
                dic.Add("WEIGHTACTUAL", Weightactual);
                dic.Add("WEIGHTJUDGE", Weightjudge);
                dic.Add("RPAGSPEC", Rpagspec);
                dic.Add("RPAGACTUAL", Rpaactual);
                dic.Add("RPAJUDGE", Rpajudge);
                dic.Add("RPATSSPEC", Rpatsspec);
                dic.Add("RPATSACTUAL", Rpatsactual);
                dic.Add("RPATSJUDGE", Rpatsjudge);
                dic.Add("BPSPEC", Bpspec);
                dic.Add("BPACTUAL", Bpactual);
                dic.Add("BPJUDGE", Bpjudge);
                dic.Add("RESULTREMARKS", Resultremarks);
            }
            
            if (UpdateExpApplyInfo(context, dic))
            {
                if (Page1 == "ExpList")
                {
                    context.Response.Write(success("Experiment/ExpList.aspx"));
                }
                else
                {
                    context.Response.Write(success("Harmful/SkillJudgeList.aspx"));
                }
            }
            else
            {
                context.Response.Write(failure());
            }

        }

        /// <summary>
        /// 申请实验
        /// </summary>
        /// <param name="context"></param>
        /// <param name="dic"></param>
        /// <returns></returns>
        public bool UpdateExpApplyInfo(HttpContext context, Dictionary<string, object> dic)
        {
            return ledgerbll.ExpApplyRoutine(dic);
        }

        #region 提示信息
        /// <summary>
        /// 操作失败(无参数)
        /// </summary>
        /// <returns></returns>
        public string failure()
        {
            return "{\"statusCode\":\"300\", \"message\":\"操作失败\"}";
        }
        /// <summary>
        /// 操作失败(有参数)
        /// </summary>
        /// <param name="str">错误提示</param>
        /// <returns></returns>
        public string failure(string str)
        {
            return "{\"statusCode\":\"300\", \"message\":\"操作失败!" + str + "\"}";
        }
        /// <summary>
        /// 操作成功(无参数)
        /// </summary>
        /// <returns></returns>
        public string success()
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\",\"navTabId\":\"editLedger\", \"callbackType\":\"closeCurrent\"}";
        }

        public string success1()
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\"}";
        }

        /// <summary>
        /// 操作成功(有参数)
        /// </summary>
        /// <param name="str">信息</param>
        /// <param name="navTabId">页面指向</param>
        /// <returns></returns>
        public string success(string str, string navTabId)
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!" + str + "\",\"navTabId\":\"" + navTabId + "\"}";
        }
        public string successfoward(string str, string url)
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!" + str + "\",\"navTabId\":\"forward\",\"forwardUrl\":\"" + url + "\"}";
        }
        public string success(string navTabId)
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\",\"callbackType\":\"closeCurrent\",\"navTabId\":\"" + navTabId + "\"}";
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}